package com.shakespace.artofandroid.chapter07anim

import android.animation.ObjectAnimator
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.shakespace.artofandroid.R
import com.shakespace.firstlinecode.global.start
import kotlinx.android.synthetic.main.activity_anim.*

class AnimActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_anim)

        tv_animation.setOnClickListener {
            start(AnimationActivity::class.java)
            overridePendingTransition(R.anim.act_enter, R.anim.act_exit)
        }

        tv_animator.setOnClickListener {
            start(AnimatorActivity::class.java)
            overridePendingTransition(R.anim.act_enter, R.anim.act_exit)
        }

        tv_change_width.setOnClickListener {
//            ObjectAnimator.ofInt(tv_demo, "width", tv_demo.dp2px(200f), tv_demo.dp2px(600f)).start()
//            ObjectAnimator.ofInt(ViewWrapper(tv_demo), "width", tv_demo.dp2px(100f), tv_demo.dp2px(300f)).start()
            ObjectAnimator.ofInt(ViewWrapper(tv_demo), "width",500).start()
        }
    }

    inner class ViewWrapper(private val view: View) {
        fun getWidth(): Int {
            return view.layoutParams.width
        }

        fun setWidth(width: Int) {
            view.layoutParams.width = width
            view.requestLayout()
        }
    }
}
